<template>
  <div class="tree-item">
    <span class="i1">{{ item.name }}</span>
    <span class="i1">{{ item.nanager }}</span>
    <span class="i2">负责人</span>
    <el-dropdown class="i3" @command="commandEvent">
      <span>
        <span>操作</span>
        <i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item command="add">添加子部门</el-dropdown-item>
          <el-dropdown-item v-if="!item.isTop" command="look"
            >查看部分</el-dropdown-item
          >
          <el-dropdown-item v-if="!item.isTop" command="del"
            >删除部门</el-dropdown-item
          >
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: 'TreeItem',
  props: ['item'],
  methods: {
    commandEvent (command) {
      switch (command) {
        case 'add':
          // 把当前项传给弹框
          this.$bus.$emit('show', true, this.item)
          break
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.tree-item {
  display: flex;
  align-items: center;
  .i1 {
    flex: 1;
  }
  .i2,
  .i3 {
    width: 80px;
    text-align: right;
  }
}
</style>
